﻿namespace Snipps.Controls
{
    using System.Windows;
    using System.Windows.Controls;

    public class CloseButton : Button
    {
        static CloseButton()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(CloseButton), new FrameworkPropertyMetadata(typeof(CloseButton)));
        }

        public CloseButton()
        {
            Click += (sObj, eArgs) =>
                {
                    if (Command != null)
                    {
                        return;
                    }

                    if (ParentWindow != null)
                    {
                        ParentWindow.Close();
                    }
                };
        }

        private Window ParentWindow
        {
            get
            {
                return Window.GetWindow(this);
            }
        }
    }
}